package com.mawujun.util;

import java.text.NumberFormat;

import org.springframework.beans.propertyeditors.CustomNumberEditor;
import org.springframework.util.StringUtils;

/**
 * 主要用于转换基本类型，如int long 等，
 * @author mawujun
 *
 */
public class MyCustomNumberEditor extends CustomNumberEditor {

	public MyCustomNumberEditor(Class numberClass, boolean allowEmpty)
			throws IllegalArgumentException {
		super(numberClass, allowEmpty);
		// TODO Auto-generated constructor stub
	}
	
	public MyCustomNumberEditor(Class numberClass, NumberFormat numberFormat, boolean allowEmpty) throws IllegalArgumentException {
		super(numberClass,numberFormat, allowEmpty);
	}
	
//	/**
//	 * Coerce a Number value into the required target class, if necessary.
//	 */
//	public void setValue(Object value) {
//		if(value==null){//如果没有获取到，就用bean中的默认值，不设置值
//			return;
//		}
//		if((value instanceof String) && "".equals(((String)value).trim())) {
//			return;
//		}
//		super.setValue(value);
//	}
	
	/**
	 * Parse the Number from the given text, using the specified NumberFormat.
	 */
	public void setAsText(String text) throws IllegalArgumentException {
		if (!StringUtils.hasText(text)) {
			// Treat empty String as null value.
			//setValue(null);
			return;
		}
		System.out.println(text);
		super.setAsText(text);
	}

}
